package com.atguigu.assionexcel.thread;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.TimeUnit;

/**
 * @author senior   代码测试：超时退出   offer() <--> poll()
 * @create 2021-11-30 8:28
 */
public class QueenBlock {
    public static void main(String[] args) throws InterruptedException {
        //定义一个阻塞队列，空间大小为3
        ArrayBlockingQueue<String> arrayBlockingQueue = new ArrayBlockingQueue<>(3);
       //添加元素
        arrayBlockingQueue.offer("a");
        arrayBlockingQueue.offer("asd231a");
        arrayBlockingQueue.offer("Fasdfa");
        //超出队列长度时，设置超时退出 : 超过给定时间自动退出
        //arrayBlockingQueue.offer("GHGHSD",3L, TimeUnit.SECONDS);

        System.out.println(arrayBlockingQueue.poll());  //a
        System.out.println(arrayBlockingQueue.poll());  //asd231a
        System.out.println(arrayBlockingQueue.poll());  //Fasdfa
        System.out.println(arrayBlockingQueue.poll(3L,TimeUnit.SECONDS));   //阻塞不停止等待，null



    }
}
